text: Be more selective when selecting on focus-in
authorMatthias Clasen <mclasen@redhat.com>
Fri, 26 Jun 2020 19:49:39 +0000 (15:49 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 26 Jun 2020 19:49:39 +0000 (15:49 -0400)
We don't want to select on focus-in when the focus
comes from a child. The case where this does harm
is when you activate copy or paste actions from the
context menu. We close the menu before triggering the
action, and if that causes the text in the entry to
be selected, unexpected things happen, since the action
applies to the current selection.

Fixes: #2869
gtk/gtktext.c

index 67400607a94ac50596f2c9d97450f150e1116c03..ff6fde8e5bd7a38cf5c7fc7abf9c0d041b7f130a 100644 (file)
@@ -3193,11 +3193,15 @@ gtk_text_grab_focus (GtkWidget *widget)
   GtkText *self = GTK_TEXT (widget);
   GtkTextPrivate *priv = gtk_text_get_instance_private (self);
   gboolean select_on_focus;
+  GtkWidget *prev_focus;
+
+  prev_focus = gtk_root_get_focus (gtk_widget_get_root (widget));
 
   if (!GTK_WIDGET_CLASS (gtk_text_parent_class)->grab_focus (GTK_WIDGET (self)))
     return FALSE;
 
-  if (priv->editable && !priv->in_click)
+  if (priv->editable && !priv->in_click &&
+      !(prev_focus && gtk_widget_is_ancestor (prev_focus, widget)))
     {
       g_object_get (gtk_widget_get_settings (widget),
                     "gtk-entry-select-on-focus",